/**
 * 格式化金额字符串（或金额数字）
 * @returns {string} 格式化好在字符串 eg: 1,123,456.02
 */
export default function format_money(money: number | string) {
	const money_str = money.toString();
	const money_arr = money_str.split('.');
	const money_integer_str = money_arr[0];
	const str_arr = [] as string[];
	let spliter_idx = 0;
	for (let i = money_integer_str.length; i > 0; i--) {
		str_arr.push(money_integer_str[i - 1]);
		if (spliter_idx && spliter_idx < money_integer_str.length - 1 && (spliter_idx + 1) % 3 === 0) {
			str_arr.push(',');
		}
		spliter_idx++;
	}
	const str_tmp = str_arr.reverse().join('');
	const money_decimal_str = money_arr.length > 1 ? '.' + money_arr[1] : '';
	return str_tmp + money_decimal_str;
}
